"""
本代码由[Tkinter布局助手]生成
官网:https://www.pytk.net
QQ交流群:905019785
在线反馈:https://support.qq.com/product/618914
"""
import random
from tkinter import *
from tkinter.ttk import *
class WinGUI(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.sexvar = StringVar(value="女")
        self.tk_label_labelName = self.__tk_label_labelName(self)
        self.tk_input_txtName = self.__tk_input_txtName(self)
        self.tk_label_mcvmeuqt = self.__tk_label_mcvmeuqt(self)
        self.tk_input_txtPhone = self.__tk_input_txtPhone(self)
        self.tk_label_labelSex = self.__tk_label_labelSex(self)
        self.tk_radio_button_Sex1 = self.__tk_radio_button_Sex1(self)
        self.tk_radio_button_sex2 = self.__tk_radio_button_sex2(self)
        self.tk_label_mcvmhwzi = self.__tk_label_mcvmhwzi(self)
        self.tk_select_box_selProvince = self.__tk_select_box_selProvince(self)
        self.tk_button_btnConfirm = self.__tk_button_btnConfirm(self)
    def __win(self):
        self.title("美国移民局登记")
        # 设置窗口大小、居中
        width = 600
        height = 500
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        
        self.resizable(width=False, height=False)
        
    def scrollbar_autohide(self,vbar, hbar, widget):
        """自动隐藏滚动条"""
        def show():
            if vbar: vbar.lift(widget)
            if hbar: hbar.lift(widget)
        def hide():
            if vbar: vbar.lower(widget)
            if hbar: hbar.lower(widget)
        hide()
        widget.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Enter>", lambda e: show())
        if vbar: vbar.bind("<Leave>", lambda e: hide())
        if hbar: hbar.bind("<Enter>", lambda e: show())
        if hbar: hbar.bind("<Leave>", lambda e: hide())
        widget.bind("<Leave>", lambda e: hide())
    
    def v_scrollbar(self,vbar, widget, x, y, w, h, pw, ph):
        widget.configure(yscrollcommand=vbar.set)
        vbar.config(command=widget.yview)
        vbar.place(relx=(w + x) / pw, rely=y / ph, relheight=h / ph, anchor='ne')
    def h_scrollbar(self,hbar, widget, x, y, w, h, pw, ph):
        widget.configure(xscrollcommand=hbar.set)
        hbar.config(command=widget.xview)
        hbar.place(relx=x / pw, rely=(y + h) / ph, relwidth=w / pw, anchor='sw')
    def create_bar(self,master, widget,is_vbar,is_hbar, x, y, w, h, pw, ph):
        vbar, hbar = None, None
        if is_vbar:
            vbar = Scrollbar(master)
            self.v_scrollbar(vbar, widget, x, y, w, h, pw, ph)
        if is_hbar:
            hbar = Scrollbar(master, orient="horizontal")
            self.h_scrollbar(hbar, widget, x, y, w, h, pw, ph)
        self.scrollbar_autohide(vbar, hbar, widget)
    def __tk_label_labelName(self,parent):
        label = Label(parent,text="姓名",anchor="center", )
        label.place(x=120, y=50, width=50, height=30)
        return label
    def __tk_input_txtName(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=221, y=49, width=150, height=30)
        return ipt
    def __tk_label_mcvmeuqt(self,parent):
        label = Label(parent,text="手机号",anchor="center", )
        label.place(x=119, y=117, width=50, height=30)
        return label
    def __tk_input_txtPhone(self,parent):
        ipt = Entry(parent, )
        ipt.place(x=220, y=120, width=150, height=30)
        return ipt
    def __tk_label_labelSex(self,parent):
        label = Label(parent,text="性别",anchor="center", )
        label.place(x=117, y=185, width=50, height=30)
        return label
    def __tk_radio_button_Sex1(self,parent):
        rb = Radiobutton(parent,text="男",value="男",variable=self.sexvar)
        rb.place(x=218, y=182, width=80, height=30)
        return rb
    def __tk_radio_button_sex2(self,parent):
        rb = Radiobutton(parent,text="女",value="女",variable=self.sexvar)
        rb.place(x=323, y=181, width=80, height=30)
        return rb
    def __tk_label_mcvmhwzi(self,parent):
        label = Label(parent,text="来自",anchor="center", )
        label.place(x=121, y=242, width=50, height=30)
        return label
    def __tk_select_box_selProvince(self,parent):
        cb = Combobox(parent, state="readonly", )
        cb['values'] = ("安徽","福建","河南","江苏")
        cb.place(x=219, y=242, width=150, height=30)
        return cb
    def __tk_button_btnConfirm(self,parent):
        btn = Button(parent, text="确定", takefocus=False,)
        btn.place(x=272, y=323, width=50, height=30)
        return btn
class Win(WinGUI):
    def __init__(self, controller):
        self.ctl = controller
        super().__init__()
        self.__event_bind()
        self.__style_config()
        self.ctl.init(self)
    def __event_bind(self):
        self.tk_button_btnConfirm.bind('<Button-1>',self.ctl.doSave)
        pass
    def __style_config(self):
        pass
if __name__ == "__main__":
    win = WinGUI()
    win.mainloop()